<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../layui/css/layui.css?v=1" media="all">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <script src="../../js/jquery/1.x/jquery.js?v=1"></script>
    <script src="../../layui/layui.js?v=1" charset="utf-8"></script>
    <script src="../../js/config.js?v=1"></script>
    <script src="../../js/public.js?v=1"></script>
    <script src="../../js/function.js?v=1"></script>
    <link rel="stylesheet" href="../../css/public.css?v=1">
    <link rel="stylesheet" href="../../css/follow/list.css?v=1">
</head>
<body>
<div class="container" style="min-width: 900px">
    <div class="search-box">
        <div class="table-title">
            <p>搜索</p>
            <!--<div class="table-title-right">
                <a href="javascript:;" class="search-show">普通搜索<img src="../../img/sanjiao_lanse.png"></a>
            </div>-->
        </div>
        <div class="search-main">
            <form class="layui-form" id="searchForm">
                <div class="search-main-left">
                    <div class="layui-form-item">
                        <label class="layui-form-label">编号</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" name="barcode" type="text" placeholder="请用扫描枪扫描或输入编号">
                        </div>
                    </div>
                    <div class="layui-form-item search-date">
                        <label class="layui-form-label">下次随访日期</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" name="next_followup_start" type="text" placeholder="请选择开始日期"
                                   id="start_time">
                            <span><i class="layui-icon layui-icon-right"></i></span>
                            <input class="layui-input" name="next_followup_end" type="text" placeholder="请选择终止日期"
                                   id="ent_time">
                            <div class="clear"></div>
                        </div>
                    </div>
                </div>
                <div class="search-main-center">
                    <div class="layui-form-item">
                        <label class="layui-form-label">患者姓名</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" lay-verify="name" lay-verType="tips" name="name" type="text" placeholder="请输入患者患者姓名">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">标签</label>
                        <div class="layui-input-inline">
                            <div class="layui-input-inline">
                                <select name="tip" class="tip-box" id="tipSelect">
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="search-main-right">
                    <div class="layui-form-item">
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" lay-verify="cell" lay-verType="tips" name="cell" type="text" placeholder="请输入11位手机号">
                        </div>
                    </div>
                    <div class="search-main-right-button">
                        <button type="button" lay-submit="" lay-filter="searchBtn">搜索</button>
                        <button type="reset" class="reset-btn">[清空]</button>
                    </div>
                    <div class="clear"></div>
                </div>
            </form>
            <div class="clear"></div>
        </div>
    </div>
    <div class="table-body">
        <div class="table-title" style="border-bottom:1px solid #cccccc;">
            <div class="table-title-left">
                <button type="button" id="piliangSendSms">批量发短信</button>
                <button type="button" id="piliangAddTip">批量修改标签</button>
                <p>已选<span id="checkedUser">0</span>人</p>
            </div>
            <div class="table-title-right">
                <a href="./label.html">
                    <button>标签管理</button>
                </a>
            </div>
            <div class="clear"></div>
        </div>
        <form class="layui-form">
            <table class="layui-table" lay-even lay-skin="nob" style="border-top:1px solid #cccccc;margin:0;"
                   id="list-table" lay-filter="list-table">
            </table>
            <div id="page"></div>
        </form>
    </div>
    <!--<div class="pages-box">
        <div class="pages-box-right">
            <p>到第</p>
            <input type="text">
            <p>页</p>
            <button>前往</button>
        </div>
        <div class="layui-box layui-laypage layui-laypage-default">
            <a style="border-left:none;">末页</a>
        </div>
        <div class="pages" id="pages"></div>
        <div class="layui-box layui-laypage layui-laypage-default">
            <a style="border-right:none;">首页</a>
        </div>
        <div class="clear"></div>
    </div>-->
</div>

<div class="fixed-container change-center-container" id="piliangSendSmsBox">
    <div class="fixed-main">
        <div class="fixed-title">
            <p>批量发送短信</p>
            <i class="layui-icon layui-icon-close fixed-main-close"></i>
        </div>
        <div class="fixed-form">
            <p class="fixed-tip">发送给患者：<span id="user_names"></span></p>
            <ul id="sendSmsUl" class="template-list">
                <li>
                    <div class="template-content">
                        <p>温馨提醒：请于近期到上海某某医院MMC门诊进行就诊请于近期到上海某某医院MMC门诊进行就诊请于近期到上海某某医院MMC门诊进行就诊请于近期到上海某某医院MMC门诊进行就诊请于近期到上海某某医院MMC门诊进行就诊。</p>
                    </div>
                    <div class="template-radio">
                        <input type="radio" name="template_type" value="1">
                    </div>
                    <div class="clear"></div>
                </li>
                <li>
                    <div class="template-content">
                        <p>温馨提醒：请于近期到上海某某医院MMC门诊进行就诊。</p>
                    </div>
                    <div class="template-radio">
                        <input type="radio" name="template_type" value="2">
                    </div>
                    <div class="clear"></div>
                </li>
                <li>
                    <div class="template-content">
                        <p>温馨提醒：请于近期到上海某某医院MMC门诊进行就诊。</p>
                    </div>
                    <div class="template-radio">
                        <input type="radio" name="template_type" value="3">
                    </div>
                    <div class="clear"></div>
                </li>
            </ul>
            <div class="fixed-form-tip">
                <i class="layui-icon layui-icon-tips"></i>请确认发送的患者：为保持信息统一，文字不可更改。
            </div>
            <div class="fixed-form-item-confirm">
                <button type="button" class="cancel-btn">取消</button>
                <button style="background:#4777E7;color:white;" type="button" class="confirm-btn">提交</button>
            </div>
        </div>
    </div>
</div>
<div class="fixed-container change-center-container" id="piliangAddTipBox">
    <div class="fixed-main">
        <div class="fixed-title">
            <p>批量打标签</p>
            <i class="layui-icon layui-icon-close fixed-main-close"></i>
        </div>
        <div class="fixed-form">
            <div class="layui-form-item">
            <p class="fixed-tip">修改患者患者：<span id="add_tip_user_names"></span></p>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label">增加标签</div>
                <div class="fixed-tip-box add-tip-box-input">
                    <p class="fixed-tip-box-xuanze">请选择</p>
                    <!--<span>重点随访<i class="layui-icon layui-icon-close"></i></span>
                    <span>重点随访<i class="layui-icon layui-icon-close"></i></span>
                    <span>重点随访<i class="layui-icon layui-icon-close"></i></span>
                    <span>重点随访<i class="layui-icon layui-icon-close"></i></span>-->
                    <div class="fixed-tip-box-close">
                        <img src="../../img/sanjiao.png">
                    </div>
                    <div class="fixed-tip-list add-tip-list">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label">删除标签</div>
                <div class="fixed-tip-box del-tip-box-input">
                    <p class="fixed-tip-box-xuanze">请选择</p>
                    <!--<span>重点随访<i class="layui-icon layui-icon-close"></i></span>
                    <span>重点随访<i class="layui-icon layui-icon-close"></i></span>
                    <span>重点随访<i class="layui-icon layui-icon-close"></i></span>
                    <span>重点随访<i class="layui-icon layui-icon-close"></i></span>-->
                    <div class="fixed-tip-box-close">
                        <img src="../../img/sanjiao.png">
                    </div>
                    <div class="fixed-tip-list del-tip-list">
                    </div>
                </div>
            </div>
            <div class="fixed-form-item-confirm">
                <button type="button" class="cancel-btn">取消</button>
                <button style="background:#4777E7;color:white;" type="button" class="confirm-btn">提交</button>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    $(document).ready(function () {
        var userInfo = JSON.parse(getLocalStorage('userInfo'));
        $('body',parent.document).find('.change-center').hide();
        $('body',parent.document).find('.center_name').text(userInfo.center_name);
        window.onbeforeunload=function(){
            $('body',parent.document).find('.change-center').show();
            $('body',parent.document).find('.center_name').text(getLocalStorage('center_name'));
        }
        $('body',parent.document).find('.hospital').css('margin-right','20px')
        layui.use(['element', 'form', 'layer', 'laydate', 'laypage', 'table'], function () {
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var laypage = layui.laypage;
            var table = layui.table;

            var checkedUser = 0;
            $('#checkedUser').text(checkedUser);

            //筛选开始时间
            laydate.render({
                elem: '#start_time',

            });
            //筛选结束时间
            laydate.render({
                elem: '#ent_time',

            });

            // v1.1 信息校验
            form.verify({
                cell: function(value){
                    if(!new RegExp("(^$)|^1\\d{10}$").test(value)){
                        return '手机号必须11位数字';
                    }
                },
                name: function(value){
                    if(value.length > 10){
                        return '姓名不能超过10个字';
                    }
                },
            });

            $('.search-show').click(function () {
                $('.search-main').slideToggle(500, function () {
                    if ($('.search-main').css('display') == 'block') {
                        $('.search-show img').css('transform', 'rotate(180deg)');
                    } else {
                        $('.search-show img').css('transform', 'rotate(360deg)');
                    }
                });
            });

            //获取随访列表
            var userInfo = JSON.parse(getLocalStorage('userInfo'));
            var followList = '';
            var params = {
                'barcode': '',
                'name': '',
                'cell': '',
                'tip': '',
                'hosp_id': userInfo.hosp_id,
                'dept_id': userInfo.dept_id,
                'page_no':1
            };
            var templateList = '';  //短信模版列表
            var tipList = '';       //标签列表
            //获取随访列表
            //getFollowList(params);
            //获取医院标签
            getHostTip(params, form);
            //获取短信模版
            getTemplateList(params);

            //搜索
            form.on('submit(searchBtn)', function (data) {
                params.barcode = data.field.barcode;
                params.name = data.field.name;
                params.cell = data.field.cell;
                params.tip = data.field.tip;
                params.next_followup_start = data.field.next_followup_start;
                params.next_followup_end = data.field.next_followup_end;

                var next_followup_start = params.next_followup_start.replace(/-/g,'');
                var next_followup_end = params.next_followup_end.replace(/-/g,'');
                if(params.next_followup_start !== '' && params.next_followup_end !== ''){
                    if(next_followup_start > next_followup_end){
                        layer.msg('开始日期不能大于终止日期',{icon:5,time:1500});
                        return false;
                    }
                }

                //console.log(data);
                //console.log(params);return false;
                //getFollowList(params);
                ajax_get(configUrl.getFollow,params,(res)=>{
                    initPageList(res.data.total,1);
                });
            })

            //清空搜索
            $('.reset-btn').click(function(){
                $('#searchForm')[0].reset();
                //var search = {};
                params = {};
                params.hosp_id = userInfo.hosp_id;
                params.dept_id = userInfo.dept_id;
                //getFollowList(search);
                ajax_get(configUrl.getFollow,params,(res)=>{
                    initPageList(res.data.total,1);
                });
            })

            //全选
            form.on('checkbox(checkall)',function(data){
                if (data.elem.checked) {
                    $("input[type='checkbox']").prop('checked', true);
                } else {
                    $("input[type='checkbox']").prop('checked', false);
                }
                var checkedNum = 0;
                $('input[name=user_key]').each(function(){
                    var checked = $(this).prop('checked');
                    if(checked == true){
                        checkedNum += 1;
                    }
                });
                checkedUser = checkedNum;
                $('#checkedUser').html(checkedUser)
                console.log(checkedNum)
                form.render('checkbox');
            });
            //单选
            form.on('checkbox(checkbox)',function(data){
                var checkedNum = 0;
                $('input[name=user_key]').each(function(){
                    var checked = $(this).prop('checked');
                    if(checked == true){
                        checkedNum += 1;
                    }
                });
                checkedUser = checkedNum;
                $('#checkedUser').html(checkedUser)
                console.log(checkedNum)
            })


            //批量发送短信
            var user_key = [];
            $('#piliangSendSms').click(function () {
                user_key = [];
                //var user_key = $("input[name='user_key']:checked").serializeArray()
                $('input[name=user_key]').each(function(){
                    var checked = $(this).prop('checked');
                    if(checked == true){
                        user_key.push($(this).val());
                    }
                });
                if(user_key.length == 0){
                    layer.msg('请选择患者', {icon: 5, time: 1500});
                    return false;
                }
                var user_names = [];
                $.each(user_key,function(index,item){
                    var user_name = followList.data[item].name;
                    user_names.push(user_name);
                })
                user_names = user_names.join('、');
                $('#user_names').text(user_names+user_key.length+'人');
                $('#piliangSendSmsBox').show();
            })
            $('#piliangSendSmsBox .cancel-btn').click(function(){
                $('#piliangSendSmsBox').hide();
            })
            $('#piliangSendSmsBox .fixed-main-close').click(function(){
                $('#piliangSendSmsBox').hide();
            })

            //选择模版
            $('#sendSmsUl').on('click','li',function () {
                var checked = $(this).children().children('input').prop('checked');
                if(checked == false){
                    $(this).children().children('input').prop('checked',true);
                    $(this).addClass('template-checked');
                    $(this).siblings().removeClass('template-checked');
                }else{
                    //$(this).siblings().children().children('input').prop('checked',false);
                }
            })
            //批量发送短信确定
            $('#piliangSendSmsBox .confirm-btn').click(function(){
                console.log('confirm-btn');
                var template_type = $('input[name=template_type]:checked').val();
                if(typeof (template_type) == 'undefined' || template_type == null){
                    layer.msg('请选择短信模版', {icon: 5, time: 1500});
                    return false;
                }
                var params = {
                    'user_ids' : '',
                    'visit_levels':1,
                    'cells':[],
                    'hosp_id':userInfo.hosp_id,
                    'dept_id':userInfo.dept_id,
                    'doc_id':getLocalStorage('doc_id'),
                    'template_type': template_type
                };
                var user_ids = [];
                var cells = [];
                $.each(user_key,function(index,item){
                    var user_id = followList.data[item].user_id;
                    var user_cell = followList.data[item].cell;
                    user_ids.push(user_id);
                    cells.push(user_cell);
                })
                params.user_ids = user_ids.join(',');
                params.cells = cells.join(',');
                console.log(params);
                var loadindex = layer.load();
                ajax_post(configUrl.saveSmsNotice, params, (res) => {
                    layer.close(loadindex);
                    console.log(res);
                    if (res.status == 0) {
                        layer.msg('发送成功', {icon: 1, time: 1000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5, time: 1500});
                    }
                })
            })

            //批量修改标签
            var add_tag_ids = [];
            var del_tag_ids = [];
            $('#piliangAddTip').click(function(){
                user_key = [];
                //var user_key = $("input[name='user_key']:checked").serializeArray()
                $('input[name=user_key]').each(function(){
                    var checked = $(this).prop('checked');
                    if(checked == true){
                        user_key.push($(this).val());
                    }
                });
                if(user_key.length == 0){
                    layer.msg('请选择患者', {icon: 5, time: 1500});
                    return false;
                }
                var user_names = [];
                $.each(user_key,function(index,item){
                    var user_name = followList.data[item].name;
                    user_names.push(user_name);
                })
                user_names = user_names.join('、');
                $('#add_tip_user_names').text(user_names+user_key.length+'人');

                //如果add_tag_ids>0，隐藏请选择
                if(add_tag_ids.length >0){
                    $('.add-tip-box-input .fixed-tip-box-xuanze').hide();
                }else{
                    $('.add-tip-box-input .fixed-tip-box-xuanze').show();
                }
                if(del_tag_ids.length >0){
                    $('.del-tip-box-input .fixed-tip-box-xuanze').hide();
                }else{
                    $('.del-tip-box-input .fixed-tip-box-xuanze').show();
                }
                $('#piliangAddTipBox').show();
            });
            $('#piliangAddTipBox .cancel-btn').click(function(){
                $('#piliangAddTipBox').hide();
                $('.fixed-tip-list').hide();
                add_tag_ids == [];
                del_tag_ids == [];
            });
            $('#piliangAddTipBox .fixed-main-close').click(function(){
                $('#piliangAddTipBox').hide();
                $('.fixed-tip-list').hide()
                add_tag_ids == [];
                del_tag_ids == [];
            });
            //增加标签点击出现下拉
            $('#piliangAddTipBox .fixed-tip-box-close').click(function(e){
                /*var that = this;
                $(this).siblings('.fixed-tip-list').slideToggle(250,function(){
                    //$(that).parent().parent().siblings().children().children('.fixed-tip-list').slideUp(250)
                });*/
                if ($(this).siblings('.fixed-tip-list').css("display") == "none") {
                    $(this).siblings('.fixed-tip-list').slideDown(250);
                } else {
                    $(this).siblings('.fixed-tip-list').slideUp(250);
                }
                e = e || event; stopFunc(e);
            });
            document.onclick = function (e) {
                $(".fixed-tip-list").slideUp(250);
            }
            //阻止向上冒泡
            $('.fixed-tip-list').bind("click",function(e){
                e = e || event;stopFunc(e)
            })
            function stopFunc(e) {
                e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
            }

            //增加标签点击事件
            $('.add-tip-list').on('click','.fixed-tip-list-item',function(event){
                var key = $(this).attr('data-key');
                var tip_id = tipList[key].id;
                var name = tipList[key].name;
                console.log($.inArray(tip_id,add_tag_ids));
                if($.inArray(tip_id,add_tag_ids) != -1){
                    add_tag_ids.splice($.inArray(tip_id,add_tag_ids),1);
                    $('.add-tip-key'+key).remove();
                    $(this).removeClass('fixed-tip-list-item-checked')
                }else{
                    add_tag_ids.push(tipList[key].id);
                    var str = '<span class="add-tip-key'+key+'">'+name+'<i class="layui-icon layui-icon-close" data-id="'+tip_id+'" data-key="'+key+'"></i></span>'
                    $('.add-tip-box-input').append(str);
                    $(this).addClass('fixed-tip-list-item-checked');
                    $('.add-tip-box-input .fixed-tip-box-xuanze').hide();
                }
                console.log(add_tag_ids);
            })
            //删除标签列表内的元素
            $('.add-tip-box-input').on('click','span i',function(){
                var id = $(this).attr('data-id')
                var key = $(this).attr('data-key');
                console.log(key)
                add_tag_ids.splice($.inArray(id,add_tag_ids),1);
                $('.add-tip-list-item'+key).removeClass('fixed-tip-list-item-checked');
                $(this).parent().remove();
            });

            /*删除标签操作--------------------------------------------------*/
            $('.del-tip-list').on('click','.fixed-tip-list-item',function(){
                var key = $(this).attr('data-key');
                var tip_id = tipList[key].id;
                var name = tipList[key].name;
                console.log($.inArray(tip_id,del_tag_ids));
                if($.inArray(tip_id,del_tag_ids) != -1){
                    del_tag_ids.splice($.inArray(tip_id,del_tag_ids),1);
                    $('.del-tip-key'+key).remove();
                    $(this).removeClass('fixed-tip-list-item-checked')
                }else{
                    del_tag_ids.push(tipList[key].id);
                    var str = '<span class="del-tip-key'+key+'">'+name+'<i class="layui-icon layui-icon-close" data-id="'+tip_id+'" data-key="'+key+'"></i></span>'
                    $('.del-tip-box-input').append(str);
                    $(this).addClass('fixed-tip-list-item-checked');
                    $('.del-tip-box-input .fixed-tip-box-xuanze').hide();
                }
                console.log(add_tag_ids);
            })
            //删除标签列表内的元素
            $('.del-tip-box-input').on('click','span i',function(){
                var id = $(this).attr('data-id')
                var key = $(this).attr('data-key');
                console.log(key)
                add_tag_ids.splice($.inArray(id,add_tag_ids),1);
                $('.del-tip-list-item'+key).removeClass('fixed-tip-list-item-checked');
                $(this).parent().remove();
            });

            //批量加标签提交
            $('#piliangAddTipBox .confirm-btn').click(function(){
                /*if(add_tag_ids.length == 0){
                    layer.msg('请选择增加标签', {icon: 5, time: 1500});
                }
                if(del_tag_ids.length == 0){
                    layer.msg('请选择删除标签', {icon: 5, time: 1500});
                }*/
                var add_tag_ids_str = add_tag_ids.join(',');
                var del_tag_ids_str = del_tag_ids.join(',');
                var user_ids = [];
                $.each(user_key,function(index,item){
                    var user_id = followList.data[item].user_id;
                    user_ids.push(user_id);
                })
                user_ids = user_ids.join(',');
                var data =  {
                    "hospital_id":userInfo.hosp_id,
                    "department_id":userInfo.dept_id,
                    "patient_ids":user_ids,
                    "add_tag_ids":add_tag_ids_str,
                    "del_tag_ids":del_tag_ids_str,
                    "doc_id":getLocalStorage('doc_id')
                };
                var loadindex = layer.load();
                ajax_post(configUrl.tagsAssign,data,(res)=>{
                    console.log(res);
                    layer.close(loadindex);
                    if (res.status == 0) {
                        layer.msg('操作成功', {icon: 1, time: 1000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5, time: 1500});
                    }
                })

            })

            function initPageList(count,curr_page){
                laypage.render({
                    elem: 'page',
                    count: count,
                    curr:curr_page,
                    prev: '《',
                    next: '》',
                    first: '首页',
                    last: '末页',
                    jump:function(obj){
                        params.page_no = obj.curr;
                        getFollowList(params);
                    },
                });
            }
            ajax_get(configUrl.getFollow,params,(res)=>{
                initPageList(res.data.total,1);
            });

            //获取随访数据
            function getFollowList(params) {
                ajax_get(configUrl.getFollow, params, (res) => {
                    console.log(res);
                    followList = res.data;
                    if (res.status == 0) {
                        //$('#dataList').empty();
                        lists = res.data;
                        var listsTmp = [];
                        $.each(lists.data, function (index, item) {
                            var tips = '';
                            $.each(item.tip_name,function(tip_index,tip_item){
                                tips += '<div class="tip-item"><p>'+tip_item+'</p></div>';
                            });
                            /*if(item.tip_name.length>2){
                                $.each(item.tip_name,function(tip_index,tip_item){
                                    tips += '<div class="tip-item"><p>'+tip_item+'</p></div>';
                                    if(tip_index == 1){
                                        return false;
                                    }
                                });
                                tips +='<div class="tip-item-checkmore"><p>…</p></div>';
                            }else{
                                $.each(item.tip_name,function(tip_index,tip_item){
                                    tips += '<div class="tip-item"><p>'+tip_item+'</p></div>';
                                });
                            }*/
                            str = {
                                "checkbox":'<input type="checkbox" name="user_key" value="'+index+'" lay-skin="primary" lay-filter="checkbox">',
                                "name": '<a href="javascript:;" onclick="jumpContactList('+index+')"><div><img src="../../img/patient_username.png"><p>' + item.name + '</p></div><div><img src="../../img/patient_phone.png"><p>' + item.cell + '</p></div><div><img src="../../img/follow_3.png"><p>' + item.barcode + '</p> </div></a>',
                                "visit_at": '<div><p>首诊：<span>' + item.first_visit_at + '</span></p></div><div><p>最新：<span>'+item.first_visit_at+'</span></p></div>',
                                //'tip_name': '<div><p>重点随访</p></div><div><p>高血糖高血压</p></div>',
                                'tip_name': tips,
                                'remaining_days': item.remaining_days < 0?'已过期':item.remaining_days,
                                'next_followup': item.next_followup,
                                //'state': item.state == 0 ? '<i class="layui-icon layui-icon-close" style="color:red;"></i>' : '<i class="layui-icon layui-icon-ok" style="color:green;"></i>',
                                'state': checkState(item.count_down,item.state),
                                'caozuo': '<a href="javascript:;" onclick="jumpContactList('+index+')" title="随访记录"><img src="../../img/lianxijilu.png" style="margin-right:10px;" class="contactListImg"></a><a href="javascript:;" onclick="sendSms(' + index + ')" title="发送短信"><img src="../../img/fasongduanxin.png" ></a>',
                            };
                            listsTmp.push(str)
                        });
                        table.render({
                            elem: "#list-table",
                            cols: [[ //标题栏
                                {field: 'checkbox',title:'<input type="checkbox" lay-skin="primary" lay-filter="checkall">',width:80 },
                                {field: 'name', title: '患者信息'},
                                {field: 'visit_at', title: '就诊信息'},
                                {field: 'tip_name', title: '标签',width:170},
                                {field: 'remaining_days', title: '距离天数'},
                                {field: 'next_followup', title: '下次随访日期'},
                                {field: 'state', title: '联系状态'},
                                {field: 'caozuo', title: '操作'},
                            ]]
                            , data: listsTmp
                            , page: false
                            , even: true
                        })
                    }
                });
            }

            function checkState(count_down,state){
                if(count_down !== ''){
                    return count_down;
                }else{
                    if(state == 0){
                        return '<i class="layui-icon layui-icon-close" style="color:red;"></i>';
                    }else{
                        return '<i class="layui-icon layui-icon-ok" style="color:green;"></i>';
                    }
                }
            }

            //获取医院标签
            function getHostTip(params, form) {
                ajax_get(configUrl.hospTags, {hospital_id: params.hosp_id, department_id: params.dept_id}, (res) => {
                    console.log(res);
                    //增加搜索框的
                    tipList = res.data.list;
                    $('.tip-box').append('<option value="0">请选择</option>')
                    $.each(res.data.list, function (index, item) {
                        str = '<option value="' + item.id + '">' + item.name + '</option>';
                        $('#tipSelect').append(str);
                    });
                    form.render();
                    //增加批量打标签的
                    $.each(res.data.list,function(index,item){
                        var str = '<div class="fixed-tip-list-item add-tip-list-item'+index+'" data-key="'+index+'"><p>'+item.name+'</p><i class="layui-icon layui-icon-ok"></i></div>';
                        $('.add-tip-list').append(str)
                    });

                    $.each(res.data.list,function(index,item){
                        var str = '<div class="fixed-tip-list-item del-tip-list-item'+index+'" data-key="'+index+'"><p>'+item.name+'</p><i class="layui-icon layui-icon-ok"></i></div>';
                        $('.del-tip-list').append(str)
                    });
                });
            }

            //获取短信模版列表
            function getTemplateList(params){
                ajax_get(configUrl.getCustomTemplate,{hospital_id: params.hosp_id,department_id: params.dept_id},(res)=>{
                    console.log(res)
                    if(res.status == 0){
                        templateList = res.data;
                        $('#sendSmsUl').empty();
                        $.each(templateList,function(index,item){
                            var str = '<li><div class="template-content"><p>'+item.name+':'+item.content+'</p></div><div class="template-radio"><input type="radio" name="template_type" value="'+item.type+'"></div><div class="clear"></div></li>';
                            $('#sendSmsUl').append(str);
                        });
                    }else{
                        layer.msg(res.msg, {icon: 5, time: 1500});
                    }
                })
            }

            jumpContactList = function(index){
                var userInfo = followList.data[index];
                var mianbaoxieSex = '';
                if(userInfo.sex == 1){
                    mianbaoxieSex = '女';
                }else{
                    mianbaoxieSex = '男';
                }
                var iframe_title = '<a class="mianbaoxie" href="javascript:;" data-href="./follow/list.html" data-title="随访管理"><p style="color:#4777E7;display: inline;">随访管理</p></a> / '+'随访管理详情'+' <p style="color:#FE9987;display:inline;">'+userInfo.name+' | '+mianbaoxieSex+' | '+userInfo.age+'岁</p>';
                //$('body',parent.document).find('#iframe-title').html(iframe_title);
                saveLocalStorage('patient_id',userInfo.user_id)
                window.location.href='./contact_records.html';
                //window.location.href='./contact_records.html?patient_id=' + userInfo.user_id;
            };

            sendSms = function (index) {
                user_key = [];
                user_key.push(index);
                console.log(user_key);
                var user_names = [];
                $.each(user_key,function(index,item){
                    var user_name = followList.data[item].name;
                    user_names.push(user_name);
                })
                user_names = user_names.join('、');
                $('#user_names').text(user_names);
                $('#piliangSendSmsBox').show();
            }
        });
    });
</script>
</html>